<%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2021/4/1
  Time: 15:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>


    <link href="${pageContext.request.contextPath}/css/bootstrap.min.css" type="text/css" rel="stylesheet">
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.1.1.min.js"></script>
</head>
<body>

<h1 align="center">用户修改</h1>

<form class="form-horizontal">

    <div class="form-group">
        <input type="hidden" id="sysId" value="${a.sysId}">
        <label class="col-md-4" align="right">用户名：</label>
        <div class="col-md-4">
            <input type="text" id="name" value="${a.sysName}" class="form-control">
        </div>
    </div>
    <div class="form-group">
        <label class="col-md-4" align="right">密码：</label>
        <div class="col-md-4">
            <input type="password" id="pwd" value="${a.sysPwd}" class="form-control">
        </div>
    </div>

    <div class="form-group">
        <label class="col-md-4" align="right">确认密码：</label>
        <div class="col-md-4">
            <input type="password" id="surePwd" value="${a.sysPwd}" class="form-control">

        </div>
    </div>

    <div class="form-group">
        <label class="col-md-4"></label>
        <div class="col-md-4">
            <input type="button" class="btn btn-success btn-sm" onclick="update()" value="修改">
        </div>
    </div>

    <br>
    <span id="info"  style="color:red;position: absolute;left:30%" ></span>


</form>
</body>
<script>
    //修改方法
    function update() {
        var sysId  = $("#sysId").val();
        var name  = $("#name").val();
        var pwd  = $("#pwd").val();
        var surePwd  = $("#surePwd").val();
        //判断密码和确认密码是否一致
        if(pwd != surePwd){
            alert("密码和确认密码不一致");
        }else{
            //ajax请求
            $.ajax({
                url :"${pageContext.request.contextPath}/admin/editAjax",
                type:"post",
                data:{"sysId":sysId,"sysName":name,"sysPwd":pwd},
                contentType: "application/x-www-form-urlencoded",
                dataType:"json",
                success:function (data) {
                    console.log(data);
                    //alert(data.info);
                    $("#info").text(data.info);
                    if(data.info=="修改成功"){
                        window.location.href="${pageContext.request.contextPath}/admin/list";
                    }

                }
            })
        }

    }
</script>

</html>
